#include "ledtcp.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define DEV_PORT 5005
ledTcp::ledTcp(QObject *parent) :
    QObject(parent)
{
    qDebug() << "ledip 1:" << sysInfo->ledIp1<<sysInfo->ledIp2;
    this->udp_socket_led1 = new QUdpSocket(this);
    this->udp_socket_led1->bind(QHostAddress::Any,DEV_PORT);
    connect(this->udp_socket_led1,SIGNAL(readyRead()),this,SLOT(socket_udp_rec()));
    this->udp_socket_led2 = new QUdpSocket(this);
    this->udp_socket_led2->bind(QHostAddress::Any,DEV_PORT);
    //connect(this->udp_socket_led2,SIGNAL(readyRead()),this,SLOT(socket_udp_rec()));
}

void ledTcp::socket_udp_rec()
{
    QByteArray buffer = this->udp_socket_led1->readAll();
    qDebug() << buffer;
    //使用 GB2312 编码接收数据，这样才可以显示中文
}

void ledTcp::socket_led_display(QByteArray info)
{
    this->udp_socket_led1->writeDatagram(info,QHostAddress(sysInfo->ledIp1),DEV_PORT);
    this->udp_socket_led2->writeDatagram(info,QHostAddress(sysInfo->ledIp2),DEV_PORT);
    qDebug()<<"send socket_led_display";
}
